var tools = require("../../pros_modules/tools");
module.exports = function (sequelize) {
    var model = sequelize.define("user", {
        "id": {type: sequelize.DataTypes.INTEGER, autoIncrement: true, primaryKey: true},
        "username": {type: sequelize.DataTypes.STRING(100), allowNull: false, comment: "用户登录账号"},
        "password": {type: sequelize.DataTypes.STRING(100), allowNull: false, comment: "用户登录密码"},
        "email": {type: sequelize.DataTypes.STRING(100), allowNull: true, comment: "用户登录邮箱"},
        "mobilePhone": {type: sequelize.DataTypes.STRING(15), allowNull: true, comment: "用户登录手机"},
        "qq": {type: sequelize.DataTypes.STRING(20), allowNull: true, comment: "用户QQ号码"},
        "isEmailLogin": {
            type: sequelize.DataTypes.CHAR(1),
            defaultValue: "0",
            comment: "是否可以使用email登录:1 是，0：否"
        }, "isMobilePhoneLogin": {
            type: sequelize.DataTypes.CHAR(1),
            defaultValue: "0",
            comment: "是否可以使用mobilePhone登录:1 是，0：否"
        }, "isAdmin": {
            type: sequelize.DataTypes.CHAR(1),
            defaultValue: "0",
            comment: "是否为管理员:1 是，0：否"
        }, "isQQLogin": {
            type: sequelize.DataTypes.CHAR(1),
            defaultValue: "0",
            comment: "是否能使用QQ登录:1 是，0：否"
        }
    }, {
        "tableName": "user"
    });

    model.initRelation = function () {
        model.belongsTo(db.models.trueFalse, {as: "isEmailLoginObj", foreignKey: "isEmailLogin", constraints: false});
        model.belongsTo(db.models.trueFalse, {
            as: "isMobilePhoneLoginObj",
            foreignKey: "isMobilePhoneLogin",
            constraints: false
        });
        model.belongsTo(db.models.trueFalse, {as: "isAdminObj", foreignKey: "isAdmin", constraints: false});
        model.belongsTo(db.models.trueFalse, {as: "isQQLoginObj", foreignKey: "isQQLogin", constraints: false});
        model.belongsTo(db.models.userInfo, {as: "userInfoObj", foreignKey: "id", constraints: false});
    }

    model.initData = new Array();
    model.initData.push({
        id: 1,
        username: "liuhuan",
        password: tools.md5("123456"),
        email: "289283175@qq.com",
        mobilePhone: "15921258458",
        qq: "289283175",
        isAdmin: "1"
    });
    model.initData.push({
        id: 2,
        username: "haoshuhong",
        password: tools.md5("123456"),
        email: "999999999@qq.com",
        mobilePhone: "15999999999",
        qq: "99999999"
    });
};